package com.uek.handler;

import com.uek.pojo.BaseDict;
import com.uek.pojo.CstCustomer;
import com.uek.pojo.CstCustomerDetail;
import com.uek.service.CustomerServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    CustomerServiceImpl customerService;
    @RequestMapping("/add/aa")
    public String customeradd(Model model){
        List<BaseDict> sjlyList = customerService.getBaseDict("商机来源");
        List<BaseDict> hyList = customerService.getBaseDict("客户行业");
        List<BaseDict> jbList = customerService.getBaseDict("客户级别");
        model.addAttribute("sjlyList",sjlyList);
        model.addAttribute("hyList",hyList);
        model.addAttribute("jbList",jbList);
        return "customer/add";
    }

    @RequestMapping("/list")
    public String customerlist(Model model){
        List<CstCustomer> allCstCustmoer = customerService.getAllCstCustmoer();
        model.addAttribute("allCstCustmoer",allCstCustmoer);
        return "customer/list";
    }

    @RequestMapping(value = "/addCustomer", method = RequestMethod.POST)
    public ModelAndView addCustomer(CstCustomer cstCustomer,CstCustomerDetail cstCustomerDetail){
        ModelAndView modelAndView = new ModelAndView();
        int i = customerService.addCustomer(cstCustomer);
        int i1 = customerService.addCustomerDetail(cstCustomerDetail);
        modelAndView.setViewName("success");
        return modelAndView;



    }


}
